<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加积分</title>
</head>

<?php
include_once("base-class.php");

//新建sae数据库类
$mysql = new SaeMysql();

//获取需要修改的员工ID号传入
$roster_id=intval($_GET["roster_id"]);

//获取操作标识传入
$action=$_POST["action"];
$action= string::un_script_code($action);
$action= string::un_html($action);

$gift_list=$mysql->getData("SELECT `gift_code`,`gift_item`,`gift_score`FROM `gift` where`gift_status`=1 ORDER BY `gift`.`gift_code` ASC");

$roster_list=$mysql->getData("SELECT `roster_name` FROM `roster` where`roster_status`=1 ORDER BY `roster`.`roster_number` ASC");
if($action=="update")
{
    //获取表单传入数据
	$list_name=$_POST["name"];
	$list_code=$_POST["code"];
    $list_socre=$_POST["score"];
	
	
    //检测必填项目
    if(!$list_name || !$list_code || !$list_socre )
    {
		echo "<script>alert('请填写将表单完整！');history.back();</Script>";
		exit;    
    }	
	
	//默认参数
    $nowtime=date("Y/m/d H:i:s",time());
	$list_status=0;
	
	//新增
	$sql = "insert into list 
	(list_name,list_code,list_money,
	list_addtime,list_status) 
	values 
	('$list_name','$list_code','$list_socre',
	'$nowtime','$list_status')";
	$mysql->runSql( $sql );

    if( $mysql->errno() != 0 )
    {
        echo "<script>alert('".$mysql->errmsg() ."');history.back();</Script>";
        exit;
    }
    else
    {
        echo "<script>alert('操作成功！');location='list_add.php';</Script>";
        exit;    
    }	
}




?>

<body>
<p align="center">添加积分</p>
<form id="form1" name="form1" method="post" action="" >
  <p>姓名：
    <label for="roster_name"></label>
    <label for="name"></label>
    <select name="name" id="name">
    	
      <option value="0">为谁添加积分</option>
      	<?php
			foreach($roster_list as $value)
			{
				echo "<option value=\"$value[roster_name]\">$value[roster_name]</option>";	
			}
	  	?>
    </select>
  </p>
  <p>
    <label for="select">积分项：</label>
    <select name="code" size="1" id="code">
      <option value="0">请选择积分项</option>
		<?php
			//列出所有积分项
			foreach($gift_list as $value)
			{
				echo "<option value=\"$value[gift_code]\">$value[gift_code].$value[gift_item]($value[gift_score])</option>";
			}
        ?>
      <option value="x02" selected="selected">x02</option>
    </select>
  </p>
  <p>分值：
    <label for="score"></label>
    <input type="text" name="score" id="score" />
  </p>
  <p>
  	<input type="hidden" name="action"  value="update">
    <input type="submit" name="提交" id="提交" value="提交" />
  </p>
</form>
<p>&nbsp;</p>
</body>
</html>